{ NULL }
};
-static char *
-parse_deploy_name_from_path (GFile *osdir,
- GFile *path)
-{
- ot_lfree char *relpath = g_file_get_relative_path (osdir, path);
- const char *last_dash;
-
- g_assert (relpath);
- last_dash = strrchr (relpath, '-');
- if (!last_dash)
- g_error ("Failed to parse deployment name %s", relpath);
-
- return g_strndup (relpath, last_dash - relpath);
-}
-
static gboolean
ensure_remote_branch (OstreeRepo *repo,
const char *remote,
ot_lobj GFile *current_deployment = NULL;
ot_lfree char *deploy_name = NULL;
ot_lobj GFile *deploy_dir = NULL;
- ot_lobj GFile *os_dir = NULL;
ot_lfree char *remote_name = NULL;
ot_lptrarray GPtrArray *subproc_args = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL;
if (!ostree_repo_check (repo, error))
goto out;
- deploy_dir = g_file_get_child (ostree_dir, "deploy");
- os_dir = g_file_get_child (deploy_dir, osname);
-
if (argc > 2)
{
target = argv[2];
goto out;
}
- deploy_name = parse_deploy_name_from_path (os_dir, current_deployment);
+ ot_admin_parse_deploy_name (ostree_dir, osname, current_deployment,
+ &deploy_name, NULL);
}
- {
- ot_lfree char *repo_arg = g_strconcat ("--repo=",
- gs_file_get_path_cached (repo_path),
- NULL);
-
- if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
- GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
- cancellable, error,
- "ostree", "pull", repo_arg, osname, NULL))
- goto out;
- }
+ if (!ot_admin_pull (ostree_dir, osname, cancellable, error))
+ goto out;
{
ot_lfree char *opt_ostree_dir_arg = g_strconcat ("--ostree-dir=",
#include "ot-admin-builtins.h"
#include "ot-admin-functions.h"
+#include "ostree.h"
#include "otutil.h"
#include <unistd.h>
#include <stdlib.h>
#include <glib/gi18n.h>
+static gboolean opt_reboot;
+
static GOptionEntry options[] = {
+ { "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after a successful upgrade", NULL },
{ NULL }
};
GFile *ostree_dir = admin_opts->ostree_dir;
gs_free char *booted_osname = NULL;
const char *osname = NULL;
+ gs_unref_object GFile *deployment = NULL;
+ gs_unref_object GFile *repo_path = NULL;
+ gs_unref_object OstreeRepo *repo = NULL;
+ gs_free char *deploy_name = NULL;
+ gs_free char *current_rev = NULL;
+ gs_free char *new_rev = NULL;
gs_free char *ostree_dir_arg = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL;
}
else
{
- if (!ot_admin_get_active_deployment (NULL, &booted_osname, NULL, cancellable, error))
+ if (!ot_admin_get_booted_os (&booted_osname, NULL,
+ cancellable, error))
goto out;
if (booted_osname == NULL)
{
}
osname = booted_osname;
}
+
+ if (!ot_admin_get_current_deployment (ostree_dir, osname, &deployment,
+ cancellable, error))
+ goto out;
+
+ ot_admin_parse_deploy_name (ostree_dir, osname, deployment, &deploy_name, ¤t_rev);
ostree_dir_arg = g_strconcat ("--ostree-dir=",
gs_file_get_path_cached (ostree_dir),
NULL);
-
- if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
- GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
- cancellable, error,
- "ostree", "admin", ostree_dir_arg, "pull-deploy", osname, NULL))
+
+ if (!ot_admin_pull (ostree_dir, osname, cancellable, error))
goto out;
if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
"ostree", "admin", ostree_dir_arg, "prune", osname, NULL))
goto out;
+ if (opt_reboot)
+ {
+ repo_path = g_file_get_child (ostree_dir, "repo");
+
+ repo = ostree_repo_new (repo_path);
+ if (!ostree_repo_check (repo, error))
+ goto out;
+
+ if (!ostree_repo_resolve_rev (repo, deploy_name, TRUE, &new_rev,
+ error))
+ goto out;
+
+ if (strcmp (current_rev, new_rev) != 0 && opt_reboot)
+ {
+ gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
+ cancellable, error,
+ "systemctl", "reboot", NULL);
+ }
+ }
+
ret = TRUE;
out:
if (context)
return ret;
}
-static gboolean
-ot_admin_get_booted_os (char **out_osname,
- char **out_tree,
+gboolean
+ot_admin_get_booted_os (char **out_osname,
+ char **out_tree,
GCancellable *cancellable,
- GError **error)
+ GError **error)
{
gboolean ret = FALSE;
gs_free char *ret_osname = NULL;
ot_transfer_out_value (out_ostree_dir, &ret_ostree_dir);
return ret;
}
+
+gboolean
+ot_admin_pull (GFile *ostree_dir,
+ const char *osname,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gs_unref_object GFile *repo_path = g_file_get_child (ostree_dir, "repo");
+ gs_free char *repo_arg = g_strconcat ("--repo=",
+ gs_file_get_path_cached (repo_path),
+ NULL);
+
+ return gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
+ GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
+ cancellable, error,
+ "ostree", "pull", repo_arg, osname, NULL);
+}
+
+void
+ot_admin_parse_deploy_name (GFile *ostree_dir,
+ const char *osname,
+ GFile *deployment,
+ char **out_name,
+ char **out_rev)
+{
+ gs_unref_object GFile *deploy_dir = g_file_get_child (ostree_dir, "deploy");
+ gs_unref_object GFile *os_dir = g_file_get_child (deploy_dir, osname);
+ gs_free char *relpath = g_file_get_relative_path (os_dir, deployment);
+ const char *last_dash;
+
+ g_assert (relpath);
+ last_dash = strrchr (relpath, '-');
+ if (!last_dash)
+ g_error ("Failed to parse deployment name %s", relpath);
+
+ if (out_name)
+ *out_name = g_strndup (relpath, last_dash - relpath);
+ if (out_rev)
+ *out_rev = g_strdup (last_dash + 1);
+}
GCancellable *cancellable,
GError **error);
+gboolean ot_admin_get_booted_os (char **out_osname,
+ char **out_tree,
+ GCancellable *cancellable,
+ GError **error);
+
gboolean ot_admin_get_current_deployment (GFile *ostree_dir,
const char *osname,
GFile **out_deployment,
GCancellable *cancellable,
GError **error);
+gboolean ot_admin_pull (GFile *ostree_dir,
+ const char *osname,
+ GCancellable *cancellable,
+ GError **error);
+
+void
+ot_admin_parse_deploy_name (GFile *ostree_dir,
+ const char *osname,
+ GFile *deployment,
+ char **out_name,
+ char **out_rev);
+
G_END_DECLS
#endif